<?php
/**
 * Created by PhpStorm.
 * User: chenguangpeng
 * Date: 4/27-2016
 * Time: 11:16
 * 即时通短信通知
 */

namespace Business\sms;

use Cache\Redis;

class VComSms
{
    /**
     * 校验短信验证码
     * @date   2017-02-07
     * @author Lanlc
     *
     * @param  string  $mobile  手机号
     * @param  string  $key     redis值前缀
     * @param  int     $vcode   验证码
     *
     * @return
     */
    public function ChkVerifyCode($mobile, $key,  $vcode)
    {
        $redis = new Redis();
        $code = $redis->get("$key:$mobile");
        //var_dump($code);die;
        if ($code) {
            $tmp = explode('|', $code);
            $chk_code = $tmp[0];
            //$chk_code = array_shift(explode('|', $code));
            //var_dump($chk_code);die;
            if ($vcode == $chk_code) {
                $redis->rm("$key:$mobile");
                return true;
            }
            return false;
        }
        return -1;
    }
}
